Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

196
Views
Elimine el "" adicional en "lng" en el objeto de matriz javascript

El siguiente código es para csv a matriz. Obtengo un "espacio" adicional en la salida.
Ejemplo:
salida: {lat: 42.546245, "lng": 1.601554}
esperado: {lat: 42.546245, "lng": 1.601554} Se necesita ayuda para eliminar el espacio adicional en el encabezado "lng".

 function initMap() { mapLoad(); readFiles(); } function readFiles() { const myForm = document.getElementById("myForm"); const csvFile = document.getElementById("csvFile"); function csvToArray(str, delimiter = ",") { // slice from start of text to the first \n index // use split to create an array from string by delimiter console.log(str); const headers = str.slice(0, str.indexOf("\n")).split(delimiter); // slice from \n index + 1 to the end of the text // use split to create an array of each csv value row // const rows = str.slice(str.indexOf("\n") + 1).split("\n"); const rows = str.slice(str.indexOf("\n") + 1).split("\n"); // Map the rows // split values from each row into an array // use headers.reduce to create an object // object properties derived from headers:values // the object passed as an element of the array const arr = rows.map(function (row) { const values = row.split(delimiter).map(Number); const el = headers.reduce(function (object, header, index) { object[header] = values[index]; return object; }, {}); return el; }); // return the array return arr; } myForm.addEventListener("submit", function (e) { e.preventDefault(); const input = csvFile.files[0]; const reader = new FileReader(); reader.onload = function (e) { const text = e.target.result; const data = csvToArray(text); console.log(data); mapLoad_1(data); }; reader.readAsText(input); }); }
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

puede usar la función de recorte en el encabezado

 object[header.trim()] = values[index];
about 4 years ago · Juan Pablo Isaza Report

0

Cuando obtenga el título, puede eliminar todos los espacios a través de la función trim ()

 const headers = str.slice(0,str.indexOf("\n")).trim().split(delimiter); const rows = str.slice(str.indexOf("\n") + 1).trim().split("\n");
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!